package kgc.crm.controller;

import kgc.crm.annotation.UserPower;
import kgc.crm.annotation.VerificationToken;
import kgc.crm.enums.PowerEnum;
import kgc.crm.model.Menu;
import kgc.crm.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("menu")
@CrossOrigin
public class MenuController {
    @Autowired
    private IMenuService menuService;
    //查询列表(管理系统的查询)
    @GetMapping("list/{id}")
    @VerificationToken
    @UserPower(power = PowerEnum.INDEX)
    public ResponseEntity list(@PathVariable("id") Integer id){
        return menuService.list(id);
    }
    //查询列表(当前登录用户菜单)
    //添加列表
    @PostMapping("add")
    @VerificationToken
    @UserPower(power = PowerEnum.SAVE)
    public ResponseEntity add(@RequestBody Menu menu){
        return menuService.add(menu);
    }
    //修改菜单
    @PostMapping("upd")
    @VerificationToken
    @UserPower(power = PowerEnum.UPDATE)
    public ResponseEntity upd(@RequestBody Menu menu){
        return menuService.upd(menu);
    }
    //删除菜单(逻辑删除 将状态改成禁用)
    @PostMapping("del")
    @VerificationToken
    @UserPower(power = PowerEnum.UPDATE)
    public ResponseEntity del(@RequestBody Menu menu){
        return menuService.del(menu);
    }
    //批量删除(逻辑删除 将状态改成禁用)
    @PostMapping("bath/del")
    @VerificationToken
    @UserPower(power = PowerEnum.DELETE)
    public ResponseEntity bathDel(@RequestBody String ids){
        return menuService.bathDel(ids);
    }
}
